package com.example.mqspring.rabiitmqbasicleverone.rabbitmqDistribute;

import com.example.mqspring.utils.RabbitMqUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

/**
 * 均衡消费
 */
public class Producer {

    static private String queue = "bobotest";

    public void configChannel(Channel channel,String queue) throws Exception {
        channel.queueDeclare(queue, false, false, false, null);
//        预获取数量.這里设置最大为1条消息
        channel.basicQos(1);
    }

    public static void main(String[] args) {
        Producer producer = new Producer();
        Connection connection = RabbitMqUtil.createConnection();
        Channel channel = null;
        try {
            channel = connection.createChannel();
            producer.configChannel(channel,queue);
            String messageDownLoad = "https://www.2008php.com/download.php?id=949230";
            //        连续疯狂发送消息
            for (int i = 0; i<10;i++) {
                channel.basicPublish("",queue,null,messageDownLoad.getBytes());
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
